library CommonUtils requires /*
    */ Practicals /*
    */ Dto /*
    */

    struct CommonUtils extends array

        /*
        --------------------------------------------------------------------------
        # 添加限时闪电链 单位-点
        --------------------------------------------------------------------------
        * param 
        */
        private static method anon_7cb24a22 takes nothing returns nothing
            local Dto dto = GetTimerData(GetExpiredTimer())
            call MoveLightningEx(dto.m_lightning, false, GetUnitX(dto.m_unit), GetUnitY(dto.m_unit), GetUnitZ(dto.m_unit) + 60.00, /*
            */dto.getReals(0), dto.getReals(1), GetSurfaceZ(dto.getReals(0), dto.getReals(1)))
            set dto.m_int = dto.m_int - 1
            if dto.m_int < 0 then
                call DestroyLightning(dto.m_lightning)
                set dto.m_lightning = null
                call dto.destroy()
            elseif dto.m_int <= dto.m_int1 and dto.m_int > 0 then
                call SetLightningColor(dto.m_lightning, 1, 1, 1, I2R(dto.m_int) / I2R(dto.m_int1))
            endif
        endmethod
        static method addLightningAtUnitToXYTimed takes string se, unit u, real dx, real dy, real timeout returns nothing
            local Dto dto = Dto.create()
            set dto.m_unit = u
            call dto.setReals(0, dx)
            call dto.setReals(1, dy)
            set dto.m_int = R2I(timeout / 0.02)
            set dto.m_int1 = dto.m_int
            set dto.m_lightning = AddLightningEx(se, false, GetUnitX(u), GetUnitY(u), GetUnitZ(u) + 60.00, dx, dy, GetSurfaceZ(dx, dy))
            call TimerStart(dto.getTimer(), 0.02, true, function thistype.anon_7cb24a22)
        endmethod

        /*
        --------------------------------------------------------------------------
        # 添加限时闪电链 单位-单位
        --------------------------------------------------------------------------
        * param 
        */
        private static method anon_86ac23b6 takes nothing returns nothing
            local Dto dto = GetTimerData(GetExpiredTimer())
            call MoveLightningEx(dto.m_lightning, false, GetUnitX(dto.m_unit), GetUnitY(dto.m_unit), GetUnitZ(dto.m_unit) + 60.00, /*
            */GetUnitX(dto.m_unit1), GetUnitY(dto.m_unit1), GetUnitZ(dto.m_unit1) + 60.00)
            set dto.m_int = dto.m_int - 1
            if dto.m_int < 0 then
                call DestroyLightning(dto.m_lightning)
                set dto.m_lightning = null
                call dto.destroy()
            elseif dto.m_int <= dto.m_data and dto.m_int > 0 then
                call SetLightningColor(dto.m_lightning, 1, 1, 1, I2R(dto.m_int) / I2R(dto.m_data))
            endif
        endmethod
        static method addLightningAtUnitToUnitTimed takes string se, unit ua, unit ub, real timeout returns nothing
            local Dto dto = Dto.create()
            set dto.m_unit = ua
            set dto.m_unit1 = ub
            set dto.m_int = R2I(timeout / 0.02)
            set dto.m_data = dto.m_int
            set dto.m_lightning = AddLightningEx(se, false, GetUnitX(ua), GetUnitY(ua), GetUnitZ(ua) + 60.00, GetUnitX(ub), GetUnitY(ub), GetUnitZ(ub) + 60.00)
            call TimerStart(dto.getTimer(), 0.02, true, function thistype.anon_86ac23b6)
        endmethod

        /*
        --------------------------------------------------------------------------
        # 在单位位置播放音效
        --------------------------------------------------------------------------
        * @param  string  file          播放文件
        * @param  integer timeout       播放超时时间
        * @param  unit    u             单位
        * @param  real    delay         延迟播放时间
        * @return
        */
        private static method anon_e336b15b takes nothing returns nothing
            local Dto dto = GetTimerData(GetExpiredTimer())
            call RunSoundOnUnit(NewSound(dto.m_string, dto.m_int, false, true), dto.m_unit)
            call dto.destroy()
        endmethod
        static method delayRunSoundOnUnit takes string file, integer timeout, unit u, real delay returns nothing
            local Dto dto = Dto.create()
            set dto.m_unit = u
            set dto.m_string = file
            set dto.m_int = timeout
            call TimerStart(dto.getTimer(), delay, false, function thistype.anon_e336b15b)
        endmethod
        
    endstruct

endlibrary